<?php
namespace app\backend\controller;
use think\Db;
use think\Controller;
class Graph extends Controller
{
	public function index()
    {
    	$ret=db('order')->where("status='1'")->field("SUM(order_total) as result,FROM_UNIXTIME(creat_time,'%Y-%m') as month")->group('month')->select();
    	dump($ret);
    	$sale=db('product')->field("SUM(product_sales) as amount")->group('product_sort')->select();
    	$date1="2019-3-10 11:05:00";
        $date2="2019-3-11 13:00:00";
        $date3="2019-2-8  9:40:00";
        $date4="2019-2-18  9:55:00";
        $date5="2019-1-18  16:50:00";
        $date6="2019-1-27  19:20:00";
        $date7="2019-1-01  00:00:00";
       dump(strtotime($date1)); //=>1380601394
       dump(strtotime($date2)); //=>1380601394
       dump(strtotime($date3)); //=>1380601394
       dump(strtotime($date4)); //=>1380601394
       dump(strtotime($date5)); //=>1380601394
       dump(strtotime($date6)); //=>1380601394
       dump(strtotime($date7)); //=>1380601394
       dump($sale);
    	
    	return view("./graph/index");

    }
    public function graph()
    {
    	
    	
    	return view("./graph/graph");

    }
    public function test1()
    {
    	return $this->fetch();
    }
     public function test2()
    {
    	return $this->fetch();
    }
    public function graph_data()
    {
    	$ret=db('order')->where("status='1'")->field("SUM(order_total) as result,FROM_UNIXTIME(creat_time,'%Y-%m') as month")->group('month')->select();
        //dump($ret);
    	for($i=0;$i<count($ret);$i++)
    	{   
    		$sqldata[$i]['month']=$ret[$i]['month'];
    		$sqldata[$i]['result']=$ret[$i]['result'];
    	}
    	$sqldata_json=json_encode($sqldata);
    	echo $sqldata_json;


    }
    public function data()
    {
    	$ret=db('product')->field("SUM(product_sales) as amount")->group('product_sort')->select();
    	$sqldata[0]['name']='景点';
    	$sqldata[1]['name']='酒店';
    	$sqldata[2]['name']='餐厅';
    	for($i=0;$i<count($ret);$i++)
    	{
    		$sqldata[$i]['value']=$ret[$i]['amount'];
    	}
    	
    	$sqldata_json=json_encode($sqldata);
    	echo $sqldata_json;
    }
    public function data1()
    {
    	
    	//$ret=db('echarts')->select();
    	$ret=db('order')->where("status='1'")->field("SUM(order_total) as result,FROM_UNIXTIME(creat_time,'%Y-%m-%d') as day")->group('day')->select();
    	$ret1=db('order')->where("status='0'")->field("SUM(order_total) as result,FROM_UNIXTIME(creat_time,'%Y-%m-%d') as day")->group('day')->select();


    	for($i=0;$i<count($ret);$i++)
    	{   $sqldata[$i]['day']=$ret[$i]['day'];
    		$sqldata[$i]['result']=$ret[$i]['result'];
    		

    	}
    	for($i=0;$i<count($ret1);$i++)
    	{   $sqldata1[$i]['day']=$ret1[$i]['day'];
    		$sqldata1[$i]['result']=$ret1[$i]['result'];
    		

    	}
    	$sqldata_json=json_encode($sqldata);
    	$sqldata_json1=json_encode($sqldata1);
    	
    	
    	$ret[0]=$sqldata_json;
    	$ret[1]=$sqldata_json1;
    	
    	return(json_encode($ret)) ;

    	
    	//echo $sqldata_json1;
    }
    public function data2()
    {
    	$ret1=db('shopcart')->where("status='0'")->field("count(shopcart_id) as result,FROM_UNIXTIME(shopcart_time,'%Y-%m') as month")->group('month')->select();
        //dump($ret1);
    	for($i=0;$i<count($ret1);$i++)

    	{   
    		$sqldata[$i]['result']=$ret1[$i]['result']*200;
    		$sqldata[$i]['month']=$ret1[$i]['month'];
    		

    	}

    	$sqldata_json=json_encode($sqldata);
    	echo $sqldata_json;

    	
    }
}